import './style.scss'
import {ColumnFilterMethodParams, VXETable} from 'vxe-table'
import {handleClearEvent} from "./pluginUtils";

// @ts-ignore
let coms = require.context('./com', false, /.(ts)$/)
coms = coms.keys().reduce((a, b) => {
  const va = coms(b).default
  a = {
    ...a,
    [b.replace('./', '').replace('.ts', '')]: va
  }
  return a
}, {})

declare module 'vxe-table' {
  interface RendererMapOptions {
    defaultFilterMethod?(params: ColumnFilterMethodParams): boolean;
  }
}

/**
 * 基于 vxe-table 表格的适配插件，用于兼容 element-ui 组件库
 */
export const VXETablePluginElement = {
  install({interceptor, renderer}: typeof VXETable) {
    renderer.mixin(coms)
    interceptor.add('event.clearFilter', handleClearEvent)
    interceptor.add('event.clearActived', handleClearEvent)
    interceptor.add('event.clearAreas', handleClearEvent)
  }
}

